package com.yc.cloud.business;

import com.yc.cloud.socket.service.impl.SocketClientImpl;
import com.yc.cloud.socket.utils.SocketClientUtil;
import lombok.extern.slf4j.Slf4j;
import org.java_websocket.handshake.ServerHandshake;
import org.springframework.stereotype.Service;

/**
 * @author 杨智杰
 * @since 2021/11/30 11:13
 */
@Slf4j
@Service
public class Demo2Socket extends SocketClientImpl {

    {
        SocketClientUtil.socketClient = this;
    }

    @Override
    public void onOpen(ServerHandshake serverHandshake) {
        System.out.println(serverHandshake.getHttpStatusMessage());
        sendMessage("hello");
    }

    @Override
    public void onMessage(String s) {
        if ("1".equals(s)) {

        } else if ("2".equals(s)) {

        } else if ("3".equals(s)) {

        } else if ("4".equals(s)) {

        }
        log.info("收到消息:" + s);
        sendMessage(s);
    }

    @Override
    public void onClose(int i, String s, boolean b) {
        System.out.println(i + "???" + s + "???" + b);
    }

    @Override
    public void onError(Exception e) {
        System.out.println(e.getMessage());
    }
}
